package com.example.hp.service.impl;

import com.example.hp.entity.Instructors;
import com.example.hp.dao.InstructorsDao;
import com.example.hp.service.InstructorsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Instructors)表服务实现类
 *
 * @author makejava
 * @since 2024-12-15 16:49:38
 */
@Service("instructorsService")
public class InstructorsServiceImpl implements InstructorsService {
    @Resource
    private InstructorsDao instructorsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param instructorId 主键
     * @return 实例对象
     */
    @Override
    public Instructors queryById(Integer instructorId) {
        return this.instructorsDao.queryById(instructorId);
    }

    /**
     * 分页查询
     *
     * @param instructors 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Instructors> queryByPage(Instructors instructors, PageRequest pageRequest) {
        long total = this.instructorsDao.count(instructors);
        return new PageImpl<>(this.instructorsDao.queryAllByLimit(instructors, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param instructors 实例对象
     * @return 实例对象
     */
    @Override
    public Instructors insert(Instructors instructors) {
        this.instructorsDao.insert(instructors);
        return instructors;
    }

    /**
     * 修改数据
     *
     * @param instructors 实例对象
     * @return 实例对象
     */
    @Override
    public Instructors update(Instructors instructors) {
        this.instructorsDao.update(instructors);
        return this.queryById(instructors.getInstructorId());
    }

    /**
     * 通过主键删除数据
     *
     * @param instructorId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer instructorId) {
        return this.instructorsDao.deleteById(instructorId) > 0;
    }
}
